#include<iostream>
using namespace std;
const int N = 210;
int n, m;
int a[N][N];
int f[N][N], dp[N][N];
int main()
{
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			cin >> a[i][j];
		}
	}
	f[1][1] = a[1][1] > 0 ? a[1][1] : 1 + a[1][1] * (-1);
	dp[1][1] = a[1][1] > 0 ? a[1][1] : 1;
	for (int i = 2; i <= m; i++) {
		f[1][i] = f[1][i - 1];
		int x = dp[1][i - 1] + a[1][i];
		if (x > 0)dp[1][i] = x;
		else if (!x) {
			dp[1][i] = 1;
			f[1][i]++;
		}
		else {
			dp[1][i] = 1;
			f[1][i] += (-1) * a[1][i];
		}
	}
	for (int i = 2; i <= n; i++) {
		f[i][1] = f[i - 1][1];
		int x = dp[i - 1][1] + a[i][1];
		if (x > 0)dp[i][1] = x;
		else if (!x) {
			dp[i][1] = 1;
			f[i][1]++;
		}
		else {
			dp[i][1] = 1;
			f[i][1] += (-1) * a[i][1];
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (i == 1 || j == 1)continue;
			int k1 = f[i - 1][j];
			int k2 = f[i][j - 1];
			int z1 = dp[i - 1][j];
			int z2 = dp[i][j - 1];
			int x1 = z1 + a[i][j];
			int x2 = z2 + a[i][j];
			if (i == 3 && j == 3) {
				cout << "k1==" << k1 << endl;
				cout << "k2==" << k2 << endl;
				cout << "x1==" << x1 << endl;
			}
			if (!x1) {
				z1 = 1;
				k1++;
			}
			else if(x1<0) {
				z1 = 1;
				k1 += (-1) * x1;
				k1++;
			}
			if (!x2) {
				z2 = 1;
				k2++;
			}
			else if(x2<0) {
				z2 = 1;
				k2 += (-1) * x2;
				k2++;
			}
			if (i == 3 && j == 3) {
				cout << "k1==" << k1 << endl;
				cout << "k2==" << k2 << endl;
			}
			f[i][j] = min(k1, k2);
			if (f[i][j] == k1)dp[i][j] = z1;
			else dp[i][j] = z2;
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			cout << dp[i][j] << " ";
		}
		cout << endl;
	}
	cout << f[n][m] << endl;
	return 0;
}